#include "mypushbutton.h"
#include <QMouseEvent>
#include<QDebug>

myPushButton::myPushButton(QString normalimg,QString pressimg)
{
    this->normalimgPath=normalimg;
    this->pressimgPath=pressimg;

    QPixmap pix;
    bool ret=pix.load(normalimg);
    if(!ret)
    {
        qDebug()<<"图片加载失败";
        return;
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));
}
void myPushButton::mousePressEvent(QMouseEvent *e)
{
    QPixmap pix;
    bool ret=pix.load(this->pressimgPath);
    if(!ret)
    {
        qDebug()<<"图片加载失败";
        return;
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));

    return QPushButton::mousePressEvent(e);
}
void myPushButton::mouseReleaseEvent(QMouseEvent *e)
{
    QPixmap pix;
    bool ret=pix.load(this->normalimgPath);
    if(!ret)
    {
        qDebug()<<"图片加载失败";
        return;
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));

    return QPushButton::mouseReleaseEvent(e);
}
